#include "customizedit.h"



CustomizeEdit::CustomizeEdit(QWidget *parent)
{
    // 文本改变时 触发这个信号限制长度
    connect(this, &QLineEdit::textChanged, this, &CustomizeEdit::LimitTextLength);
}

void CustomizeEdit::SetMaxLength(int maxLen)
{
     _maxLen = maxLen;
}

void CustomizeEdit::focusOutEvent(QFocusEvent * e)
{
    emit SigFoucusOut();
    QLineEdit::focusOutEvent(e);

}

void CustomizeEdit::LimitTextLength(QString text)
{
    if(_maxLen<=0)
        return;
    QByteArray byteArray = text.toUtf8();
    if(byteArray.size() > _maxLen){
        byteArray = byteArray.left(_maxLen);
        this->setText(QString::fromUtf8(byteArray));
    }
}
